home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Sep / di9809am / Compont / Sample2 / TapiForm.pas < prev   
Pascal/Delphi Source File  |  1998-06-29  |  3KB  |  115 lines

  1. { This project accompanies the article written by Alan Moore
  2.   and Ken Kyler on TAPI basics }
  3.  
  4. unit TapiForm;
  5.  
  6. interface
  7.  
  8. uses
  9.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  10.   StdCtrls, ExtCtrls, Mask, ComCtrls, Tapi, TAPIcomp;
  11.  
  12. type
  13.   TTapiCallManager = class(TForm)
  14.     Label1: TLabel;
  15.     ePhoneNum: TMaskEdit;
  16.     btnDial: TButton;
  17.     btnHangup: TButton;
  18.     kkamTAPI1: TkkamTAPI;
  19.     procedure btnDialClick(Sender: TObject);
  20.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure btnHangupClick(Sender: TObject);
  23.   //  procedure FormDestroy(Sender: TObject);
  24.  public
  25.  private
  26.     { Private declarations }
  27.     procedure PhoneNumChange;
  28.     { Public declarations }
  29.   end;
  30.  
  31. var
  32.    TapiCallManager : TTapiCallManager;
  33.  
  34. const
  35.   Ver = $00010004;  // API version accepted (1.4) [Windows 95]
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40.  
  41. procedure TTapiCallManager.btnDialClick(Sender: TObject);
  42. var
  43.   DialResult: string;
  44.   StringListPlaceHolder : TStringList;
  45. begin
  46.   DialResult := kkamTAPI1.Dial;
  47.   if DialResult='Success' then
  48.     begin
  49.       ShowMessage(DialResult);
  50.       btnDial.Enabled := False;
  51.       btnHangup.Enabled := True;
  52.     end;
  53. end;
  54.  
  55. procedure TTapiCallManager.FormCloseQuery(Sender: TObject;
  56.                             var CanClose: Boolean);
  57. var
  58.   StringListPlaceHolder : TStringList;
  59. begin
  60.   StringListPlaceHolder := TStringList.Create;
  61.   // if the custom call manager was used, make sure to free resources
  62.   if kkamTAPI1.LineIsOpen then
  63.      CanClose := kkamTAPI1.ShutdownManager;
  64.   StringListPlaceHolder.Free
  65. end;
  66.  
  67. procedure TTapiCallManager.FormCreate(Sender: TObject);
  68. var
  69.   S : string;
  70.   TheResult : LongInt;
  71.   ThePort : THandle;
  72. begin
  73.   btnHangup.Enabled := False; // No calls yet!
  74.   TheResult := 999; // Initialize to bogus number, just to make certain
  75.   PhoneNumChange; //Get Current Value (default)
  76.   kkamTAPI1.Dev := 0;  // keeping it simple!
  77.   if not kkamTAPI1.TAPI_Initialized then
  78.      // if we can't initialize, close
  79.      begin
  80.        ShowMessage('Could not initialize TAPI -- closing down');
  81.        Halt;
  82.      end
  83.   else
  84.     begin
  85.  
  86.     if NOT kkamTapi1.OpenLine(False, S) then
  87.       begin
  88.         ShowMessage('Couldn''t Open a Line; try again later');
  89.         exit;
  90.       end;
  91.     end;
  92.     // For pulse dialing, uncomment the following line:
  93.     // kkamTapi1.PulseDialing := True;
  94. end;
  95.  
  96. procedure TTapiCallManager.btnHangupClick(Sender: TObject);
  97. begin
  98.   if not kkamTAPI1.ShutdownManager then
  99.     ShowMessage('Couldn''t shut TAPI down')
  100.   else
  101.     begin
  102.       btnHangup.Enabled := false;   // disable the hangup button
  103.       btnDial.Enabled := true;      // enable the dial button
  104.     end;
  105. end;
  106.  
  107. procedure TTapiCallManager.PhoneNumChange;
  108. begin
  109.   kkamTAPI1.PhoneNumber := ePhoneNum.Text;
  110. end;
  111.  
  112.  
  113.  
  114. end.
  115.